/*
 * Copyright 2013-2019 Xia Jun(3979434@qq.com).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 ***************************************************************************************
 *                                                                                     *
 *                        Website : http://www.farsunset.com                           *
 *                                                                                     *
 ***************************************************************************************
 */
package xin.alum.aim.model;

import com.google.protobuf.Any;
import lombok.Data;
import lombok.SneakyThrows;
import xin.alum.aim.constant.AIMConstant;
import xin.alum.aim.model.proto.Packet;

/**
 * java |android 客户端请求结构
 */
@Data
public class Sent extends DBase {

    @Override
    public int getType() {
        return AIMConstant.DATA_TYPE_SENT;
    }

    public Sent() {
    }

    public Sent(String key) {
        super(key);
    }

    public Sent(String key, long timestamp) {
        super(key, timestamp);
    }

    public Sent(String key, long timestamp, com.google.protobuf.Message data) {
        super(key, timestamp);
        this.setData(data);
    }

    public Sent(String key, com.google.protobuf.Message data) {
        super(key);
        this.setData(data);
    }

    @Override
    public Packet.Sent toBuilder() {
        Packet.Sent.Builder builder = Packet.Sent.newBuilder();
        builder.setKey(this.getKey());
        builder.setTimestamp(this.getTimestamp());
        if (data != null) {
            builder.setData(Any.pack(data));
        }
        return builder.build();
    }

    @SneakyThrows
    public String toString() {
        return toJson();
    }
}
